// 1.
function flatten(arr) {
  return arr.reduce((pre, cur) => {
    return pre.concat(Array.isArray(cur) ? flatten(cur) : cur)
  }, [])
}

// 2.
function findMinAndMax(str) {
  const arr = str.split(',').map(Number)
  if(arr.length < 2) return 0
  let max = -Infinity, min = Infinity
  for(let i = 0; i < arr.length; i++) {
    if(arr[i] > max) max = arr[i]
    if(arr[i] < min) min = arr[i]
  }
  return max - min
}

// 3.
function objToString(obj) {
  let str = ''
  for(let [key, val] of Object.entries(obj)) {
    str += `${key} is ${val}, `
  }
  return str.slice(0, -2)
}

// 4.
function timeCalculator(time, add) {
  let date = new Date(`2023-03-02 ${time}`).getTime()
  let sum = 0
  add.forEach((item, idx) => {
    sum += item * 1000 * 60 ** (2 - idx)
  })
  return (new Date(date + sum)).toTimeString().slice(0, 8)
}